//
//  RCPushMessageDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-10-1.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCPushMessageDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSArray+EX.h"

@implementation RCPushMessageItem

@synthesize itemTitle = _itemTitle;
@synthesize itemUrl = _itemUrl;

-(void)dealloc{
    self.itemUrl = nil;
    self.itemTitle = nil;
    [super dealloc];
}

-(id)initWithDict:(NSDictionary *)dict{
    self = [super init];
    if (self) {
        self.itemTitle = [dict stringValueForKey:@"title" defaultValue:nil operation:NSStringOperationTypeTrim];
        self.itemUrl = [dict stringValueForKey:@"url" defaultValue:nil operation:NSStringOperationTypeTrim];
    }
    return self;
}

@end

@implementation RCPushMessageDataModel

@synthesize itemListArray = _itemListArray;

-(id)init{
    self = [super init];
    if (self) {
        _itemListArray = nil;
    }
    return self;
}

-(void)dealloc{
    self.itemListArray = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    NSArray *dictArray = [data arrayValueForKey:@"data" defaultValue:nil];
    if (nil == dictArray || [dictArray count] == 0) {
        return nil;
    }
    RCPushMessageDataModel *retObject = nil;
    retObject = [[RCPushMessageDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    
    NSMutableArray *tempArray = [[NSMutableArray alloc]initWithCapacity:[dictArray count]];
    for (int i =0; i < [dictArray count]; i++) {
        NSDictionary *dictItem = [dictArray safeObjectAtIndex:i];
        if (nil == dictItem) {
            continue;
        }
        RCPushMessageItem *item = [[RCPushMessageItem alloc]initWithDict:dictItem];
        if (nil == item) {
            continue;
        }
        [tempArray addObject:item];
        [item release];
    }
    retObject.itemListArray = [NSArray arrayWithArray:tempArray];
    [tempArray release];
    return [retObject autorelease];
}

@end
